package com.wlk.controller;

import com.wlk.pojo.Role;
import com.wlk.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/list")
    public List<User> getUsers() {
        Role role1 = new Role();
        role1.setRoleId(1);
        role1.setRoleName("管理员");
        Role role2 = new Role();
        role2.setRoleId(2);
        role2.setRoleName("超级管理员");
        User user1 = new User();
        user1.setUserId(1);
        user1.setUserName("涛哥");
        user1.setRoles(Arrays.asList(role1,role2));
        User user2 = new User();
        user1.setUserId(2);
        user1.setUserName("王乐凯");
        user1.setRoles(Arrays.asList(role1));


        return Arrays.asList(user1,user2);
    }
    @GetMapping("/detail/{userId}")
    public User getUser(@PathVariable int userId) {
        Role role1 = new Role();
        role1.setRoleId(1);
        role1.setRoleName("管理员");
        Role role2 = new Role();
        role2.setRoleId(2);
        role2.setRoleName("超级管理员");
        User user1 = new User();
        user1.setUserId(1);
        user1.setUserName("涛哥");
        user1.setRoles(Arrays.asList(role1,role2));

        if (user1.getUserId().equals(userId)) {
            return user1;
        }else{
            return null;
        }

    }

}
